package com.example.shizi;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.SavedStateHandle;

public class MyViewModel extends AndroidViewModel {
    private MutableLiveData<Integer> number;
    private MutableLiveData<Boolean> flag;
    private MutableLiveData<Integer> rightNum;
    private MutableLiveData<Integer> wrongNum;

    public MyViewModel(@NonNull Application application) {
        super(application);
    }


    public MutableLiveData<Integer> getRightNum() {
        if (rightNum == null) {
            rightNum = new MutableLiveData<>();
            rightNum.setValue(0);
        }
        return rightNum;
    }

    public MutableLiveData<Integer> getWrongNum() {
        if (wrongNum == null) {
            wrongNum = new MutableLiveData<>();
            wrongNum.setValue(0);
        }
        return wrongNum;
    }
    public MutableLiveData<Integer> getNumber() {
        if (number == null) {
            number = new MutableLiveData<>();
            number.setValue(0);
        }
        return number;
    }
    public MutableLiveData<Boolean> getFlag() {
        if (flag == null) {
            flag = new MutableLiveData<>();
            flag.setValue(true);
        }
        return flag;
    }

    public void addRightNum() {
        if (rightNum == null) {
            rightNum = new MutableLiveData<>();
            rightNum.setValue(0);
        }
        rightNum.setValue(rightNum.getValue() + 1);
    }

    public void addWrongNum() {
        if (wrongNum == null) {
            wrongNum = new MutableLiveData<>();
            wrongNum.setValue(0);
        }
        wrongNum.setValue(wrongNum.getValue() + 1);
    }

    public void add() {
        number.setValue(number.getValue() + 1);
        if (number.getValue() < 0) {
            number.setValue(0);
        }
    }

    public void clearNum() {
        if (getNumber().getValue() >= 6) {
            getNumber().setValue(getNumber().getValue() - 6);
        } else {
            getNumber().setValue(0);
        }
    }

}
